package com.wlyuan.index.controller;

import com.alibaba.fastjson.JSONObject;
import com.wlyuan.index.api.ICombineIndexService;
import com.wlyuan.index.api.dto.combine.CombineIndexFilterDTO;
import com.wlyuan.index.api.dto.combine.CombineReindexAllDTO;
import com.wlyuan.index.api.dto.combine.CombineReindexDTO;
import com.wlyuan.index.api.vo.CombineIndexSumVO;
import com.wlyuan.index.api.vo.CombineIndexVO;
import com.wlyuan.tools.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuanjie
 */
@Slf4j
@Api(tags = "合单")
@RestController
@RequestMapping("/combine")
public class CombineIndexController {
    @DubboReference(check = false)
    private ICombineIndexService combineIndexService;

    @ApiOperation("查询索引")
    @GetMapping("/{combineId:\\d+}")
    public CombineIndexVO getIndexById(@PathVariable("combineId") Long combineId) {
        return combineIndexService.getIndexById(combineId);
    }

    @ApiOperation("重建索引")
    @PostMapping("/reindex/{combineId:\\d+}")
    public void reindex(@PathVariable("combineId") Long combineId) {
        combineIndexService.reindex(combineId);
    }

    @ApiOperation("重建索引(筛选)")
    @PostMapping("/reindex")
    public void reindex(@RequestBody CombineReindexDTO reindex) {
        combineIndexService.reindex(reindex);
    }

    @ApiOperation("重建索引(全部)")
    @PostMapping("/reindexAll")
    public void reindexAll(@RequestBody CombineReindexAllDTO reindex) {
        combineIndexService.reindexAll(reindex);
    }

    @ApiOperation("合单列表")
    @PostMapping("/search")
    public Page<CombineIndexVO> search(@RequestBody CombineIndexFilterDTO filter) {
        return combineIndexService.search(filter);
    }

    @ApiOperation("合单统计")
    @PostMapping("/sum")
    public CombineIndexSumVO searchSum(@RequestBody CombineIndexFilterDTO filter) {
        return combineIndexService.searchSum(filter);
    }

    @ApiOperation("索引数据")
    @GetMapping("/insight/{combineId:\\d+}")
    public JSONObject insight(@PathVariable("combineId") Long combineId) {
        return combineIndexService.insight(combineId);
    }

    @ApiOperation("索引差异")
    @GetMapping("/diffs")
    public JSONObject diffs() {
        return combineIndexService.diffs();
    }
}
